#include "select.h"

Select::Select(vector<Expression *> * select)
{
    if(select == NULL) expressions = NULL;
    else{
        expressions = new vector<Expression *>();
        for(unsigned int i=0; i<select->size(); i++){
            expressions->push_back(select->at(i)->clone());
        }//for
    }// if-else
}

Select::~Select()
{
    if(expressions != NULL){
        for(unsigned int i=0; i< expressions->size(); i++) delete expressions->at(i);
        delete expressions; expressions = NULL;
    }// if
}

Select::Select(const Select& other)
{
    if(other.expressions != NULL){
        this->expressions = new vector<Expression *>();
        for(unsigned int i=0; i<other.expressions->size(); i++){
            this->expressions->push_back(other.expressions->at(i)->clone());
        }//for
    }else this->expressions = NULL;
}

void Select::addExpression(Expression * expression)
{
    if(expressions == NULL) expressions = new std::vector<Expression *>();
    if(expression != NULL) expressions->push_back(expression->clone());
}

string Select::toString()
{
    string str = "(";
    if(expressions != NULL){
        for(unsigned int i=0; i<expressions->size(); i++){
            str = str + expressions->at(i)->toString() + ",";
        }//for
        str.erase(str.length()-1);
    }// if
    return str + ")";
}

vector<Expression *> * Select::getSelectExpressions()
{
    return expressions;
}

Select * Select::clone()
{
    return new Select(*this);
}
